//
//  CRYWWApiManager.m
//  workWX
//
//  Created by 谢锷 on 2020/5/9.
//  Copyright © 2020 rongyiqiche Data and Technology Shanghai Co. Ltd. All rights reserved.
//

#import "CRYWWApiManager.h"
#import "WWKApi.h"
#import "work_wx_define.h"
#import "CRYTool.h"

@implementation CRYWWApiManager

+ (NSDictionary *) isInstalled {
    
    BOOL result = [WWKApi isAppInstalled];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:result ? @(CRYWorkWXCode_Installed) : @(CRYWorkWXErrorCode_UnInstalled) forKey:@"code"];
    [dic setValue:result ? CRYWorkWX_Installed : CRYWorkWX_UnInstalled forKey:@"msg"];
    return dic;
}

+ (NSDictionary *) openApp {
    
    if (![WWKApi isAppInstalled]) {
        return [self isInstalled];
    }
    BOOL result = [WWKApi openApp];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:result ? @(CRYWorkWXCode_Success) : @(CRYWorkWXCode_Error) forKey:@"code"];
    [dic setValue:result ? CRYWorkWX_Open_Suc : CRYWorkWX_Open_Error forKey:@"msg"];
    return dic;
}

+ (NSDictionary *) registerApp:(NSString *) appId
                        corpId:(NSString *) corpId
                       agentId:(NSString *) agentId {
    
    if ([CRYTool isContentNull:appId] || [CRYTool isContentNull:corpId] || [CRYTool isContentNull:agentId]) {
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        [dic setValue:@(CRYWorkWXCode_Error) forKey:@"code"];
        [dic setValue:CRYWorkWX_ID_Error forKey:@"msg"];
        return dic;
    }
    
    BOOL result = [WWKApi registerApp:appId corpId:corpId agentId:agentId];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:result ? @(CRYWorkWXCode_Success) : @(CRYWorkWXCode_Error) forKey:@"code"];
    [dic setValue:result ? CRYWorkWX_Register_Suc : CRYWorkWX_Register_Error forKey:@"msg"];
    return dic;
}

@end
